package com.zsrt.devbase.common.aspect.controller;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.zsrt.devbase.common.utils.GetIPUtil;


@Component
@Aspect
@Order(0)
public class RequestLogAspect {


    @Before("execution(* com.zsrt.devbase.controller.*.*(..))")
    public void log(JoinPoint joinPoint){
    	 RequestAttributes ra = RequestContextHolder.getRequestAttributes();  
         ServletRequestAttributes sra = (ServletRequestAttributes)ra;  
         HttpServletRequest request = sra.getRequest(); 
         String requestURI = request.getRequestURI(); 
         String ipAddr = GetIPUtil.getIpAddr(request);
         System.err.println(ipAddr);
//         String macAddress = GetMacAddress.getMacAddress(ipAddr);
         System.err.println(requestURI+"请求地址");
         System.err.println(ipAddr+"IP地址");
//         System.err.println(macAddress+"mac地址");
    }

}
